
import org.groovyflow.db.*
import com.bus.*

class ExptController {
	
	def hey(req, res){
	    def rec = new Product()
		//DbHelp.inTrx() {
			println "before doing anything req = " + rec
			
		    rec = rec.findById("1")
			println "finding rec by id, description is " + rec.description
			println "rec.id=" + rec.id
			println "old price is " + rec.price
			
			rec.addToPrice(40.01)
			println "new price is " + rec.price
			println rec.id 
			println "now rec is " + rec + " and rec is of type " + rec.getClass().getName()
			println 'attempting update'
			rec.save()
			println 'finished update'
			
			def toInsert = new Product()
			toInsert.price = 0.03
			toInsert.description = 'Wow'
			toInsert.categoryid = 2
			println "The description is " + toInsert.description
			println "toInsert is " + toInsert
			toInsert.save()
			
			println "id of newly created record is " + toInsert.id
			
			
			//This stuff isn't in the GroovyFlow practice database.
			//It's only temporary.
			//It shows an example of adding join read-only fields to the object,
			//then updates the object.
			/*def person = new Person()
			person = person.findBySql("""select person.*, client.clientname from person, 
				client where person.clientid = client.clientid 
					and person.personid = ?""", [10000401907])[0]
			println "person's clientname, which is a join-table readonly field, is " +person.clientName
			
			person.homePhone= '717710000'
			println "homephone is now " + person.homePhone
			person.save()*/

			
				
		 //}

		
		return null
	}
	
	
}

